package repository

import (
	"gin-shop-admin/dao"
	"gin-shop-admin/models"
)

func InsertOneUser(user *models.User) error {
	return dao.DB.Create(&user).Error
}

func GetAllUsers() (users []*models.User, err error) {
	if err = dao.DB.Find(&users).Error; err != nil {
		return nil, err
	}
	return
}

func GetUsers(PageNum int, PageSize int, maps interface{})(user []*models.User, err error)  {
	dao.DB.Where(maps).Offset(PageNum).Limit(PageSize).Find(&user)
	return
}

func GetUserByID(id string) (user *models.User, err error) {
	user = new(models.User)
	if err := dao.DB.Where("user_id=?", id).First(&user).Error; err != nil {
		return nil, err
	}
	return
}

func UpdateOneUser(user *models.User) (error) {
	return dao.DB.Save(user).Error
}

func DeleteUserByID(id string) (error) {
	return dao.DB.Where("user_id=?", id).Delete(&models.User{}).Error
}

